<template>
	<view class="page_1">
		<view class="box">
			<view class="top">
				<image :src="goods.url"></image>
				<view class="small_title">{{goods.goods_title}} </view>
				<view class="score">
					<view class="text">总体打分</view>
					<uni-rate :value="3" :size="16" max="5" @change="onChange"/>
					<!-- <view class="score_text">4.5分</view> -->
				</view>
				<view class="line"></view>
			</view>
			<view class="textareabox">
				<textarea maxlength="120" v-model="content" placeholder="可以从多个角度评价宝贝，可以帮助更多想买的人哦~~"></textarea>
			</view>
			<view class="addimg" v-if="imglist.length==0" @click="uploadimg()">
				<image src="../../static/xj.png"></image>
				<view>添加图片</view>
			</view>
			<view class="imgbox" v-else>
				<view class="imglist" v-for="(item,index) in imglist" :key="index">
					<image :src="item" style="border-radius: 16rpx;"></image>
					<image class="closen" src="../../static/gb.png" @click="spliceimg(index)"></image>
				</view>
				<view class="imglist" @click="uploadimg()" style="border:2rpx dashed #999999,width:33%" v-if="imglist.length<6">
					<image style="width: 66rpx;height: 60rpx; margin: 50rpx 0 10rpx 0;" src="../../static/xj.png">
					</image>
					<view>添加图片</view>
				</view>
			</view>
		</view>
		<!-- 匿名 -->
		<view class="anonymous">
			<image src="../../static/gou.png" v-if="isRadio" @click="radioNoActive"></image>
			<image src="../../static/yuan.png" v-else @click="radioNoActive"></image>
			<view class="text" @click="radioNoActive">匿名发布评论</view>
		</view>
		<!-- 底部按钮 -->
		<view style="height: 120rpx;"></view>
		<view class="btn" @click="sumbit">
			<view>提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				appraise: "", //评价
				isRadio: false, //是否选中匿名//1不匿名 2匿名     false为不不匿名
				id:'',
				goods:{},
				imglist:[],
				content:'',
				stars:'',
			};
		},
		onLoad(option) {
			this.id = option.id
			this.orderinfo(this.id)
		},
		methods: {
			//是否匿名
			radioNoActive() {
				this.isRadio = !this.isRadio//1不匿名 2匿名  false为不不匿名
			},
			//获取订单详情
			orderinfo(orderid){
				this.$http({
					url:'api/Wechat/orderDetail',
					data:{
						orderid:orderid
					}
				}).then(res=>{
					this.goods = res.data.goods[0]
				})
			},
			//添加图片
			uploadimg() {
				this.$upload(1).then(res => {
					this.imglist.push(...res)
					console.log(this.imglist, 'this.imglist', res) //item.file.full_url
				})
			},
			//删除图片
			spliceimg(index) {
				this.imglist.splice(index, 1)
			},
			sumbit(){
				if(!this.content){
					uni.showToast({
						title:'请输入评价内容',
						icon:'none'
					})
					return
				}if(!this.stars){
					uni.showToast({
						title:'请点击星级评分',
						icon:'none'
					})
					return
				}
				this.imglist = this.imglist.join(',')
				console.log(111,this.imglist)
				this.$http({
					url:'api/Wechat/add_comment',
					data:{
						orderid:this.id,
						content:this.content,
						picarr:this.imglist,
						anonymity:this.isRadio==false?1:2,//1不匿名 2匿名  false为不不匿名
						stars:this.stars,
					}
				}).then(res=>{
					uni.redirectTo({
						url:'/pages/orderGoods/orderGoods?type='+3
					})
				})
			},
			onChange(e) {
				this.stars = e.value
				// console.log(this.stars,n);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page_1{
		padding-bottom: 160rpx;
	}
	.box {
		width: 750rpx;
		min-height: 704rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 10rpx 10rpx;
		margin-top: 76rpx;
		padding: 0 30rpx 24rpx 30rpx;
		box-sizing: border-box;
		position: relative;
		display: flex;
		flex-direction: column;

		.top {
			flex-shrink: 0;
			height: 224rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;

			image {
				position: absolute;
				left: 50%;
				top: 0;
				transform: translate(-50%, -50%);
				width: 120rpx;
				height: 120rpx;
				border-radius: 7rpx 7rpx 7rpx 7rpx;
			}

			.small_title {
				margin-top: 82rpx;
				text-align: center;
				font-size: 26rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #888888;
				line-height: 1em;
			}

			.score {
				display: flex;
				align-items: center;
				justify-content: center;
				gap: 0 20rpx;
				position: relative;
				.score_text{
					font-size: 24rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #CB9852;
					position: absolute;
					right: -94rpx;
				}
				.text {
					font-size: 28rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #222222;
				}
			}

			.line {
				width: 100%;
				background: #FFFFFF;
				border: 2rpx solid #F1F1F1;
			}
		}

		.textareabox {
			width: 100%;
			// height: 372rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 20rpx 0;
		
			>textarea {
				width: 90%;
				margin: 0rpx auto;
			}
		}
		
		.addimg {
			height: 236rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: SourceHanSansCN-Medium-, SourceHanSansCN-Medium;
			font-weight: normal;
			color: #999999;
			margin-top: 20rpx;
			border: 2rpx dashed #999999;
		
			image {
				width: 66rpx;
				height: 60rpx;
				margin-top: 50rpx;
				margin-bottom: 10rpx;
			}
		}
		
		.imgbox {
			display: flex;
			flex-wrap: wrap;
			margin-top: 20rpx;
		
			.imglist {
				width: 33.3%;
				text-align: center;
				position: relative;
		
				image {
					width: 208rpx;
					height: 208rpx;
				}
		
				.closen {
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					right: 10rpx;
					top: 0;
				}
			}
		}
	}

	// 匿名，
	.anonymous {
		margin-top: 24rpx;
		width: 750rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 38rpx;
		display: flex;
		align-items: center;
		gap: 0 14rpx;

		image {
			width: 32rpx;
			height: 32rpx;
		}

		.text {
			font-size: 28rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #222222;
		}
	}
	
	// 底部按钮
	.btn{
		width: 100%;
		height: 120rpx;
		bottom: 0;
		position: fixed;
		background-color: #FFF;
		>view{
			width: 690rpx;
			margin: 10rpx auto;
			height: 84rpx;
			border-radius: 83rpx ;
			font-size: 32rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			background: linear-gradient(360deg, #F99529 0%, #F94D29 100%);
			line-height: 84rpx;
		}
	}
</style>
